var core = {};
core.idInc = 0;

core.clearSelection = function() {
    var sel ;
    if(document.selection && document.selection.empty){
        document.selection.empty();
    } else
        if(window.getSelection) {
            sel=window.getSelection();
            if(sel && sel.removeAllRanges)
                sel.removeAllRanges();
        }
};

core.escapeHTML = function(s){
	if(!s)
		return '';
	var res = s.replace(/</g, '&lt;');
	res = res.replace(/>/g, '&gt;');
	res = res.replace(/\n/g, '<br/>');
	return res;
};

core.newDiv = function(aParent, aClass){
	return core.newElement(aParent, 'div', aClass);
};

core.newElement = function(aParent, aElementName, aClass){
	var div = document.createElement(aElementName);
	if(aClass)
		$(div).addClass(aClass);
    if(aParent)
        $(aParent).append(div);
	return div;
};

core.log = function(){
    if(!DEBUG)
        return;
    var res = '';
    for (var i = 0; i<arguments.length; i++) {
        if(arguments[i]!=undefined){
            try {
                res += (arguments[i]+' ');
            } catch (exception) {
                res += ' [error] ';
            }
        }else{
            res += ' [null] ';
        }
    }
    if(core && core.desktop && core.desktop.addLogEntry)
        core.desktop.addLogEntry(res);
};

core.findElementByItsName = function(aName){
    var el = window;
    var arr = aName.split('.');
    var i = 0;
    while(el[arr[i]]){
        el = el[arr[i]];
        i++;
        if(i>=arr.length){
            return el;
        }
    }
    return null;
};

core.extendClass = function(aChild, aParent) {
    var propsToSkip = ['className', 'classInheritance', 'instanceID'];
    var p = core.findElementByItsName(aParent).prototype;
    var c = core.findElementByItsName(aChild).prototype;
  for (var i in p) {
	var fieldOk = true;
	jQuery.each(propsToSkip, function(i, e){
		if(i==e){
			fieldOk = false;
			return false;
		}
		return true;
	});
	if(fieldOk){
		c[aParent+'_'+i] = p[i];
		c[i] = p[i];		
	}
  }
  c.className = aChild;
  c.classInheritance = [];
  for(var id in p.classInheritance){
	c.classInheritance[id] = p.classInheritance[id];
  }
  c.classInheritance.push(aChild);
}

core.clearTimeout = function(aTimeoutID){
	clearTimeout(aTimeoutID);
}

core.setTimeout = function(aObject, aMethod, aTimeout){
	var args = [];
	for(var i = 3; i<arguments.length; i++){
		args.push(arguments[i]);
	}
	return setTimeout(function(){
		aMethod.apply(aObject, args);
	}, aTimeout);
}

core.Class = function (){}

core.Class.prototype.init = function(config){
	var instace = this;
	this.instanceID = config.instanceID || ('object'+(core.idInc++));
	if(config.eventHandlers){
		jQuery.each(jQuery.makeArray(config.eventHandlers), function(i, e){
			if(e && e.event && e.handler){
				instace.on(e.event, e.handler);
			}
		})
	}
};

core.Class.prototype.classInheritance = ['core.Class'];

core.Class.prototype.instanceOf = function(aClassName){
	for(var id in this.classInheritance){
		if(this.classInheritance[id]==aClassName)
			return true;
	}
	return false;
}

core.Class.prototype.superCall = function(aMethod, aArguments){
//	core.log('superCall', aMethod, this.className, this.classInheritance, aArguments);
	var currentClass = this.className;
	if(aArguments.length>0 && aArguments[aArguments.length-1] && (typeof aArguments[aArguments.length-1])=='string' ){
		var prevClass = aArguments[aArguments.length-1];
		if(prevClass.indexOf('$parent$')==0){
			currentClass = prevClass.substring(8);
		}
	}
	for(var id in this.classInheritance){
		if(this.classInheritance[id]==currentClass && id>0){
			var args = [];
			for(var i = 2; i<arguments.length; i++){
				args.push(arguments[i]);
			}
			args.push('$parent$'+this.classInheritance[id-1]);
			var f = this[this.classInheritance[id-1]+'_'+aMethod];
			if(f){
				return f.apply(this, args);
			}
		}
	}
	return null;
}

core.Class.prototype.on = function(aEvent, aFunction){
	if(!this.events)
		this.events = {};
	if(!this.events[aEvent])
		this.events[aEvent] = [];
	this.events[aEvent].push(aFunction);
    return this;
};

core.Class.prototype.fire = function(aEvent, aEventObject){
	if(!this.events)
		this.events = {};
	if(!this.events[aEvent])
		this.events[aEvent] = [];
	var e = aEventObject || {};
	e.eventName = aEvent;
	for(var id in this.events[aEvent]){
		var f = this.events[aEvent][id];
		var args = [this, e];
		for(var i = 2; i<arguments.length; i++){
			args[i] = arguments[i];
		}
		if(!f.apply(this, args))
			return false;			
	}
	return true;
};

core.Class.prototype.get = function(aEvent){
	if(!this.events)
		this.events = {};
	if(!this.events[aEvent])
		this.events[aEvent] = [];
	for(var id in this.events[aEvent]){
		var f = this.events[aEvent][id];
		var args = [this];
		for(var i = 1; i<arguments.length; i++){
			args[i] = arguments[i];
		}
        var res = f.apply(this, args);
		if(res)
			return res;
	}
	return null;
};

core.Box = function(aParams){
	this.init(aParams)
}

core.extendClass('core.Box', 'core.Class');

core.Box.prototype.processKeyDown = function(e){
	if(!this.items)
		return true;
	for(var i = 0; i<this.items.length; i++){
		var itm = this.items[i];
		var res = itm.processKeyDown(e);
		if(!res)
			return false;
	}
	return true;
}

core.Box.prototype.collectChildren = function(aClassName, aCallback){
	if(!this.items)
		return;
	for(var i in this.items){
		var itm = this.items[i];
		if(itm.instanceOf && itm.instanceOf(aClassName))
			aCallback(itm);
		if(itm.collectChildren)
			itm.collectChildren(aClassName, aCallback);
	}
}

core.Box.prototype.parentChanged = function(){
	
}

core.Box.prototype.getPosition = function(){
    var result = {
        x: 0,
        y: 0
    };
    if(this.bounds){
        result.x = this.bounds.x;
        result.y = this.bounds.y;
    }
    if(this.parent && this.parent.getPosition){
        var p = this.parent.getPosition();
        result.x += p.x;
        result.y += p.y;
    }
    return result;
}

core.Box.prototype.reParent = function(aChild, aDiv){
	aChild.parent = this;
	if(aChild.div && (this.div || aDiv)){
		$(aChild.div).appendTo(aDiv || this.div);
		aChild.parentChanged();
	}	
}

core.Box.prototype.destroy = function(aChild){
	if(this.div){
		$(this.div).remove();
	}
}

core.Box.prototype.replaceChild = function(aOldChild, aChild, aDestroyChild){
	if(!aDestroyChild)
		aDestroyChild = core.REPLACE_CHILD_HIDE;
	for(var i = 0; i<this.items.length; i++){
		var itm = this.items[i];
		if(itm==aOldChild){
			if(aDestroyChild==core.REPLACE_CHILD_DESTROY)
				aOldChild.destroy();
			if(aDestroyChild==core.REPLACE_CHILD_HIDE)
				aOldChild.hide();
            if(!this.formless)
                this.fire('childRemoved', null, aOldChild);
			aChild.tableX = aOldChild.tableX;
			aChild.tableY = aOldChild.tableY;
			aChild.tableColSpan = aOldChild.tableColSpan;
			aChild.tableRowSpan = aOldChild.tableRowSpan;
			this.items.splice(i, 1, aChild);
			this.reParent(aChild);
			if(this.dragArea){
				$(this.dragElement).appendTo(this.div);
				$(this.dragArea).appendTo(this.div);
			}
            if(!this.formless)
                this.fire('childAdded', null, aChild);
		}
	}
};

core.Box.prototype.addChild = function(aChild){
    if(!aChild)
        return;
	this.items[this.items.length] = aChild;
	this.reParent(aChild);
    if(!this.formless)
        this.fire('childAdded', null, aChild);
};

core.Box.prototype.setDirty = function(){
    this.dirty = true;
    if(!this.items)
        return;
    for (var i = 0; i < this.items.length; i++) {
        this.items[i].setDirty();
    }
};

core.Box.prototype.init = function(aParams){
	
	if(!aParams)
		aParams = {};
    this.dirty = true;
    this.componentVisible = true;
	this.superCall('init', arguments, aParams);
	this.minWidth = 0;
	this.minHeight = 0;
	this.formless = aParams.formless || false;
	this.padding = aParams.padding;
    if(this.padding!=0)
        this.padding = aParams.padding || BOX_PADDING;
//	core.log('for', this.className, 'padding is', this.padding);
	this.x = 0;
	this.y = 0;
	
	this.width = 0;
	this.height = 0;
	
//	this.xType = 'box';
	this.params = aParams;
	
//	this.items = aParams.items;
	if(!this.items)
		this.items = [];
	this.colspan = this.params.colspan || 1;
	this.rowspan = this.params.rowspan || 1;
	
	if(!this.div){
		this.div = document.createElement('div');
		$(this.div).addClass('defaultElement');
		if(this.parent)
			this.parent.div.appendChild(this.div);
		if(aParams.bodyCls)
			$(this.div).addClass(aParams.bodyCls);
	}
	if(aParams.items){
//        core.log(this.className, 'Adding items to box...', aParams.items.length);
		for(var i = 0; i< aParams.items.length; i++){
			this.addChild(aParams.items[i]);
//            core.log(i+'...');
		}
//		core.log(this.className, 'items:', this.items.length, arguments);
	}
}

core.Box.prototype.setContent = function(aItems, aColumns, aRows){
    this.items = [];
    var arr = $.makeArray(aItems);
    for (var i = 0; i < arr.length; i++) {
        this.addChild(arr[i]);
    }
    if(aColumns)
        this.params.columns = aColumns;
    if(aRows)
        this.params.rows = aRows;
};

core.Box.prototype.imagesToHTML = function(aImg){
	if(!aImg)
		return '';
	aImg = jQuery.makeArray(aImg);
	var result = '';
	jQuery.each(aImg, function(i, img){
        if(img!='')
            result += '<img src="'+img+'" class="icon"/>'
	});
	return result;
}

core.Box.prototype.imagesToHTMLSprite = function(aImg, aClass){
	if(!aImg)
		return '';
	aImg = jQuery.makeArray(aImg);
	var result = '';
	jQuery.each(aImg, function(i, img){
		result += '<img class="icon '+aClass+' '+aImg+'" src="res/core/sp.png"/>'
	});
	return result;
}

core.Box.prototype.setVisibility = function(aVisibility){
	if(this.div)
		$(this.div).css('visibility', aVisibility?'visible':'hidden');
}

core.Box.prototype.isVisible = function(){
    if(!this.componentVisible)
        return false;
    if(this.parent)
        return this.parent.isVisible();
    return true;
}

core.Box.prototype.show = function(){
    this.componentVisible = true;
	if(this.div)
		$(this.div).show();
}

core.Box.prototype.hide = function(){
    this.componentVisible = false;
	if(this.div)
		$(this.div).hide();
}

core.Box.prototype.alignElement = function(aDiv, aWidth, aHeight, aAlign, aValign, hPadding, vPadding){	
	var align = aAlign || this.params.align || 'left';
	var valign = aValign || this.params.valign || 'top';
	$(aDiv).css('text-align', align);

	var height = $(aDiv).height();
	if('top'==valign){
		$(aDiv).css('margin-top', vPadding || 0);
	}
	if('bottom'==valign){
		$(aDiv).css('margin-top', aHeight-height-(vPadding || 0));
	}
	if('middle'==valign){
		$(aDiv).css('margin-top', Math.floor((aHeight-height)/2));
	}
}

core.Box.prototype.alignBlock = function(aDiv, aWidth, aHeight, aAlign, aValign, hPadding, vPadding){
	var align = aAlign || this.params.align || 'left';
	var valign = aValign || this.params.valign || 'top';

	var width = $(aDiv).css('margin-left', 0).width();
	if('left'==align){
		$(aDiv).css('margin-left', hPadding || 0);
	}
	if('right'==align){
		$(aDiv).css('margin-left', aWidth-width-(hPadding || 0));
	}
	if('center'==align){
		$(aDiv).css('margin-left', Math.floor((aWidth-width)/2));
	}
	var height = $(aDiv).height();
//    core.log('alignBlock for ', this.className, width, height, $(aDiv).text());
	
	if('top'==valign){
		$(aDiv).css('margin-top', vPadding || 0);
	}
	if('bottom'==valign){
		$(aDiv).css('margin-top', aHeight-height-(vPadding || 0));
	}
	if('middle'==valign){
		$(aDiv).css('margin-top', Math.floor((aHeight-height)/2));
	}
//	core.log('alignBlock', this.instanceID, width, height, aWidth, aHeight, $(aDiv).text(), align, valign, hPadding, vPadding);
}

core.Box.prototype.updateLayout = function(){
	if(!this.items || this.items.length==0)
		return;
//    core.log('updateLayout', this.className, this.text);
	var columns = this.params.columns;
	if(!columns)
		columns = 'd';
	var rows = this.params.rows;
	if(!rows)
		rows = 'd';
	var arr = columns.split(',');
	this.colSizes = [];
	for(var i = 0; i<arr.length; i++){
		this.colSizes[i] = 0;

		var f = parseFloat(arr[i]);
		if(f && f<=1)
			this.colSizes[i] = f;
	}
	arr = rows.split(',');
	this.rowSizes = [];
	for(var i = 0; i<arr.length; i++){
        var indOf = arr[i].indexOf('x');
        if(indOf!=-1){
            var num = arr[i].substr(0, indOf);
            var s = arr[i].substr(indOf+1, arr[i].length);
            var f = parseFloat(s);
            for (var j = 0; j < num; j++) {
                this.rowSizes.push(f && f<=1?f:0);
            }
            continue;
        }
		var f = parseFloat(arr[i]);
        this.rowSizes.push(f && f<=1?f:0);
	}
	var rowPos = 0;
	var colPos = 0;
	var matrix = [];
	var colCount = this.colSizes.length;
	var rowCount = this.rowSizes.length;
	for (var i = 0; i < rowCount; i++) {
		var row = [];
		for (var j = 0; j < colCount; j++) {
			row.push(-1);
		};
		matrix.push(row);
	};
	
	for(var i = 0; i<this.items.length; i++){
		while(matrix[rowPos][colPos]!=-1 && rowPos<rowCount){
			colPos++;
			if(colPos>=colCount){
				colPos = 0;
				rowPos++;
			}
		}
		if(rowPos>=rowCount)
			break;
		
		var item = this.items[i];
		item.updateLayout();
		var colspan = parseInt(item.colspan);
		if(colspan==0 || !colspan)
			colspan = 1;
		var rowspan = parseInt(item.rowspan);
		if(rowspan==0 || !rowspan)
			rowspan = 1;
			
		item.tableX = colPos;
		item.tableY = rowPos;
		item.tableColSpan = colspan;
		item.tableRowSpan = rowspan;
		
		for(var j = 0; j<colspan; j++){
			for(var k = 0; k<rowspan; k++){
                if(rowPos+k>=rowCount){
                    core.log('Error! Object', this.className+', matrix '+rowCount+'x'+colCount+' row too big', rowPos+k);
                }
                if(colPos+j>=colCount){
                    core.log('Error! Object', this.className+', matrix '+rowCount+'x'+colCount+' column too big', colPos+j);
                }
				matrix[rowPos+k][colPos+j] = i;
			}
		}
	}		
	this.matrix = matrix;
	this.columnCount = colCount;
	this.rowCount = rowCount;
	
	// core.log(this.className, this.matrix);
	// for (var i = 0; i < rowCount; i++) {
	// 	core.log('line', i, this.matrix[i]);
	// };
}

core.Box.prototype.getMinWidth = function(){
	if(this.items && this.items.length>0)
		this.minWidth = this.calculateMinWidth(this.columnCount, true);
	return this.minWidth;
}

core.Box.prototype.getMinHeight = function(){
	if(this.items && this.items.length>0)
		this.minHeight = this.calculateMinWidth(this.rowCount, false);
	return this.minHeight;
}

core.Box.prototype.calculateMinWidth = function(aArrayLength, abCalculateWidth){
	var tableColSpan = 'tableColSpan';
	var minWidth = 'getMinWidth';
	var minWidths = 'minWidths';
	var tableX = 'tableX';
	
	if(!abCalculateWidth){
		tableColSpan = 'tableRowSpan';
		minWidth = 'getMinHeight';
		tableX = 'tableY';
		minWidths = 'minHeights';
	}
	
	var widths = [];
	
	for(var i = 0; i<aArrayLength; i++){
		widths[i] = 0;
	}
	
	for(var i = 0; i<this.items.length; i++){//Fill widths
		var item = this.items[i];
		var itemMinWidth = item[minWidth]();
		if(item[tableColSpan]==1){
			if(itemMinWidth>widths[item[tableX]])
				widths[item[tableX]] = itemMinWidth;			
		}
	}
	var width = (aArrayLength+1)*this.padding;
	
	for(var i = 0; i<aArrayLength; i++){
		width += widths[i];
	}
	this[minWidths] = widths;
	return width;
}

core.Box.prototype.calculateWidth = function(aArrayLength, aArray, aWidth, abCalculateWidth){
	var tableColSpan = 'tableColSpan';
	var tableX = 'tableX';
	var setWidth = 'setWidth';
	var setX = 'x';
	var minWidths = 'minWidths';
	
	if(!abCalculateWidth){
		tableColSpan = 'tableRowSpan';
		minWidth = 'minHeight';
		tableX = 'tableY';		
		setWidth = 'setHeight';
		setX = 'y';
		minWidths = 'minHeights';
	}
	
	var widths = this[minWidths];
	var width = (aArrayLength+1)*this.padding;
	
	var f = 0;
	var widthToStretch = 0;
	for(var i = 0; i<aArrayLength; i++){
		width += widths[i];
		if(aArray[i]>0){
			widthToStretch += widths[i];
			f += parseFloat(aArray[i]);
		}
	}
	
	//We have minimalWidth, next step is stretch children
	if(width<aWidth){//We have something to stretch
		var widthDif = aWidth-width;
		width = (aArrayLength+1)*this.padding;
		for (var i = 0; i < aArrayLength; i++) {//Extend width
			if(aArray[i]>0){
				widths[i] = widths[i]+Math.floor(widthDif*aArray[i]/f);
			}
			width += widths[i];
		};
	}
			
	//Widths are calculated
	for(var i = 0; i<this.items.length; i++){//Fill widths
		var item = this.items[i];
		var itemWidth = this.padding*(item[tableColSpan]-1);
		var itemX = (item[tableX]+1)*this.padding;
		for(var j = 0; j<item[tableColSpan]; j++){
			itemWidth += widths[item[tableX]+j];
		}
		for(var j = 0; j<item[tableX]; j++){
			itemX += widths[j];
		}
		item[setX] = itemX;
		item[setWidth](itemWidth);
	}	
	
	return !width?aWidth:width;
}

core.Box.prototype.setHeight = function(aHeight){
	this.height = aHeight;
	if(this.items && this.items.length>0){		
		this.height = this.calculateWidth(this.rowCount, this.rowSizes, aHeight, false);
	}
}

core.Box.prototype.setWidth = function(aWidth){
	this.width = aWidth;
	if(this.items && this.items.length>0){		
		this.width = this.calculateWidth(this.columnCount, this.colSizes, aWidth, true);
	}
}

core.Box.prototype.refresh = function(aRecalculateSize){
//	core.log(this.className, this.instanceID, this.bounds, this.div, $(this.div).css('display'));
//	this.show();
//    var calcVisible = function(aItem){
//        var res = aItem.className+'['+aItem.instanceID+']'+aItem.componentVisible;
//        if(aItem.parent)
//            res = calcVisible(aItem.parent)+'=>'+res;
//        return res;
//    }
//    core.log('resize[', aRecalculateSize, '] for', this.className, this.instanceID, 'visible', this.isVisible(), calcVisible(this));
	if(!this.bounds || !this.div || !this.isVisible())
		return false;
	if(aRecalculateSize){
//		core.log('resize(true) for', this.className, this.instanceID);
		this.refreshDimensions(this.bounds.width, this.bounds.height);
	}else{
//		core.log('resize(false) for', this.className, this.instanceID);
    }
	this.resize(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
    return true;
}

core.Box.prototype.refreshDimensions = function(aWidth, aHeight){
//	core.log('refresh', this.className, $(this.div).css('display'));
	var minWidth = this.getMinWidth();
//    core.log('item: '+this.className+', width: '+aWidth+', min: '+minWidth);
//#ifdef MOBILE
    if(aWidth<minWidth)
        aWidth = minWidth;
//#endif
	this.setWidth(aWidth);
	var minHeight = this.getMinHeight();
//#ifdef MOBILE
    if(aHeight<minHeight)
        aHeight = minHeight;
//#endif
//    core.log('item: '+this.className+', height: '+aHeight+', min: '+minHeight);
	this.setHeight(aHeight);
}

core.Box.prototype.doResize = function(aX, aY, aWidth, aHeight){
	this.refreshDimensions(aWidth, aHeight);
	this.resize(aX, aY, this.width, this.height);
}

core.Box.prototype.markLoading = function(){
    if(!this.loadingIndicatorDiv){
        this.loadingIndicatorDiv = core.newDiv(this.div, 'loading_indicator');
        this.loadingIndicatorDivImg = core.newDiv(this.loadingIndicatorDiv, 'loading_indicator_img');
        this.refresh();
    }
};

core.Box.prototype.unMarkLoading = function(){
    if(this.loadingIndicatorDiv){
        $(this.loadingIndicatorDiv).remove();
        this.loadingIndicatorDiv = null;
        this.loadingIndicatorDivImg = null;
        this.refresh();
    }
};

core.Box.prototype.makeResize = function(aX, aY, aWidth, aHeight){

}

core.Box.prototype.resize = function(aX, aY, aWidth, aHeight){
    var oldbounds = this.bounds || {
		x: -1,
		y: -1,
		width: -1,
		height: -1
    };
	this.bounds = {
		x: aX,
		y: aY,
		width: aWidth,
		height: aHeight
	};
    if(oldbounds.x!=aX || oldbounds.y!=aY || oldbounds.width!=aWidth || oldbounds.height!=aHeight)
        this.dirty = true;
	if(this.div){
        if(this.dirty){
            $(this.div).width(aWidth);
            $(this.div).height(aHeight);
            $(this.div).css('left', aX);
            $(this.div).css('top', aY);
        }
//		$(this.div).show();
        if(this.loadingIndicatorDiv){
            $(this.loadingIndicatorDiv).width(aWidth);
            $(this.loadingIndicatorDiv).height(aHeight);
            var imgSize = Math.min(aWidth, aHeight, core.LOADING_MAX_SIZE);
            $(this.loadingIndicatorDivImg).html('<img src="'+core.LOADING_FILE_NAME+'" width="'+imgSize+'" height="'+imgSize+'" class="img"/>');
            $(this.loadingIndicatorDivImg).width(imgSize);
            $(this.loadingIndicatorDivImg).height(imgSize);
            this.alignBlock(this.loadingIndicatorDivImg, aWidth, aHeight, 'center', 'middle');
        }
	}
    this.makeResize(aX, aY, aWidth, aHeight);
	this.dirty = false;
	if(this.items && this.items.length>0){
				
		for(var i = 0; i<this.items.length; i++){
			var item = this.items[i];
			item.resize(item.x, item.y, item.width, item.height);
		}
		
	}
	
}

core.ttip = {};
core.ttip.enableTooltip = function(){};

//#ifdef DESKTOP
core.ttip.SLEEP_TIME = 750;
core.ttip.CURSOR_OFFSET = 15;
core.ttip.div = core.newDiv(document.body, 'tooltip');
core.ttip.enableTooltip = function(aObject, aDiv){
    $(aDiv).mousemove(function(e){
        $(core.ttip.div).css('visibility', 'hidden');
        core.clearTimeout(core.ttip.timeoutID);
        core.ttip.timeoutID = setTimeout(function(){
            if(aObject.tooltip){
                $(core.ttip.div).html(aObject.tooltip);
                var x = e.pageX+core.ttip.CURSOR_OFFSET;
                var y = e.pageY+core.ttip.CURSOR_OFFSET;
                if(x+$(core.ttip.div).outerWidth()>$(document.body).width()){
                    x = $(document.body).outerWidth()-$(core.ttip.div).width()-core.ttip.CURSOR_OFFSET;
                }
                if(y+$(core.ttip.div).height()>$(document.body).height()){
                    y = e.pageY-core.ttip.CURSOR_OFFSET-$(core.ttip.div).height();
                }
                $(core.ttip.div).css('left', x).css('top', y).css('visibility', 'visible');

            }
        }, core.ttip.SLEEP_TIME);
        return true;
    }).mouseout(function(){
        $(core.ttip.div).css('visibility', 'hidden');
        core.clearTimeout(core.ttip.timeoutID);
        return true;
    }).mousedown(function(){
        $(core.ttip.div).css('visibility', 'hidden');
        core.clearTimeout(core.ttip.timeoutID);
        return true;
    });
};
    
//#endif

var keyDownHandler = null;

//Global keyDowns

var globalKeyHandler = function(e){
    if(desktop)
        return desktop.processKeyDown(e);
    return true;
};

if(jQuery.browser.opera)
	$(document).keypress(globalKeyHandler);
else
	$(document).keydown(globalKeyHandler);
//$(document).keyrepeat(globalKeyHandler);
